﻿using System.Drawing;
using DevExpress.XtraBars;

namespace Com.OpenCode.Framework.DevForm
{
    public class OpenCodeToolBarMenuUI : Bar
    {
        public OpenCodeToolBarMenuUI(BarManager barManager)
        {
            Manager = barManager;
            Manager.Bars.Add(this);
            InitStyle();
        }

        public OpenCodeToolBarMenuUI()
        {
            InitStyle();
        }

        protected virtual void InitStyle()
        {
            canCloseMenu = false;
            OptionsBar.DisableClose = true;
            OptionsBar.MultiLine = false;
            OptionsBar.AllowQuickCustomization = false;
            OptionsBar.DrawBorder = false;
            OptionsBar.RotateWhenVertical = false;
            OptionsBar.DisableCustomization = true;
            OptionsBar.AutoPopupMode = BarAutoPopupMode.OnlyMenu;
            DockStyle = BarDockStyle.Top;
            CanDockStyle = BarCanDockStyle.Top;
        }

        /// <summary>
        ///     添加普通项。
        /// </summary>
        public BarItem AddMenuItem(string caption, Image image)
        {
            BarItem barItem = new BarButtonItem(Manager, caption);
            barItem.Glyph = image;
            AddItem(barItem);
            return barItem;
        }

        /// <summary>
        ///     添加普通项。
        /// </summary>
        public BarItem AddMenuItem(string caption, string image)
        {
            //object obj = (Image) IconServices.BulidFromName(image);
            Image _Image = null;
           // if (obj != null)
           // {
                //_Image = (Image) IconServices.BulidFromName(image);
           // }
            return AddMenuItem(caption, _Image);
        }

        public BarItem AddMenuItem(string caption, Image image, bool begineGroup)
        {
            BarItem barItem = AddMenuItem(caption, image);
            AddItem(barItem).BeginGroup = begineGroup;
            return barItem;
        }

        public BarItem AddMenuItem(string caption, string image, bool begineGroup)
        {
            BarItem barItem = AddMenuItem(caption, image);
            AddItem(barItem).BeginGroup = begineGroup;
            return barItem;
        }

    }
}